package com.cloudm.technician.data.preferences

import android.content.SharedPreferences
import com.cloudm.technician.data.config.Config

/**
 * 作者: wesley
 * 时间: 2017/11/20
 * 描述: 接口的实现类
 */
class AppPreferencesHelper(private val preferences: SharedPreferences) : PreferencesHelper {

    override var isFirstTimeIn: Boolean
        get() = preferences.getBoolean(Config.IS_FIRST_TIME_IN, true)
        set(value) {
            preferences.edit().apply {
                putBoolean(Config.IS_FIRST_TIME_IN, value)
            }.apply()
        }

    override var isLogin: Boolean
        get() = preferences.getBoolean(Config.IS_LOGIN, false)
        set(value) {
            preferences.edit().apply {
                putBoolean(Config.IS_LOGIN, value)
            }.apply()
        }

    override var token: String?
        get() = preferences.getString(Config.USER_LOGIN_TOKEN, "")
        set(value) {
            preferences.edit().apply {
                putString(Config.USER_LOGIN_TOKEN, value)
            }.apply()
        }


    override var userId: Int
        get() = preferences.getInt(Config.USER_LOGIN_ID, -1)
        set(value) {
            preferences.edit().apply {
                putInt(Config.USER_LOGIN_ID, value)
            }.apply()
        }

}